<?php

	error_reporting(0);
	session_start();
	error_reporting(1);

	require_once "../common/PinSQL.obj";
	$pinSQL = new PinSQL();
	$pinSQLm = new PinSQL();
	
	$id = $_SESSION['id'];
	
	$pinSQL->Query("SELECT * FROM members ORDER BY username");
	$pinSQLm->Query("SELECT * FROM memberdata WHERE id='$id'");
	$rowm = $pinSQLm->FetchNextRow();
	$tagged_users = $rowm['tagged_users'];
	
	$userI = 0;
	
?>
<div class="context_message" id="context_message" style="display: none;">
	<div id="message_text"></div>
	<div style="text-align: right" id="message_choices"></div>
</div>
<span class="small">
<table>

	<tr>

<?php
	 	
	while ( $row = $pinSQL->FetchNextRow() )
	{
		$user = $row['username'];
		$userID = $row['id'];
		$pinSQLm->Query("SELECT * FROM memberdata WHERE id='$userID'");
		$rowm = $pinSQLm->FetchNextRow();
		$picurl = $rowm['picurl'];
		
		if ($userI % 2 == 0)
		{
			echo "</tr><tr>";
		}
		
		$userI++;
		
?>

	<td width="72">
<?php
		if ($picurl)
		{
		$imageSize = getimagesize("userData/$user/$picurl");
		
		if ($imageSize[0] <= 64)
		{
			$newWidth = $imageSize[0];
			$newHeight = $imageSize[1];
		} else {
			$heightFactor = $imageSize[1] / $imageSize[0];
			$newWidth = 64;
			$newHeight = $newWidth * $heightFactor;
		}
		
?>
		<img src="userData/<?php echo $user . "/" . $picurl; ?>" width="<?php echo $newWidth; ?>" height="<?php echo $newHeight; ?>" />	
<?php
		}
?>
	</td>

	<td>

<?php
		$taggedUsers = explode(",", $tagged_users);
		$isTagged = FALSE;
		for ($i=0; $i<sizeof($taggedUsers); $i++)
		{
			if ($taggedUsers[$i] == $user)
			{ $isTagged = TRUE; }
		}
?>	
		<?php if ($isTagged) { ?><img src="/img/icons/tagged_user_sm.png" /><span class="orangetext"><?php } ?>
		<a href="/members/frame.php?page=profile&user=<?php echo $user; ?>"><?php echo $row['username']; ?></a><?php if ($isTagged) { echo "</span>"; } ?>

		<span class="small"><span class="redtext"><?php echo $row['level']; ?></span></span>
		<br /><img src="/img/arrow_green.gif" /><a href="/members/frame.php?page=composemessage&touser=<?php echo $user; ?>">Send message<?php
		
		if ($row['firstname'])
		{
			echo " to " . $row['firstname'] . " " . $row['lastname'];
		}
		
		?></a>
		
<?php if ($isTagged == FALSE) { ?>
		<br /><img src="/img/arrow_yellow.gif" /><a href="javascript:AJAXAction('/members/do_action.php?actionname=taguser&user=<?php echo $user; ?>&referrer=viewusers')">Tag <?php echo $row['firstname']; ?></a>
<?php } else { ?>
		<br /><img src="/img/arrow_orange.gif" /><a href="javascript:AJAXAction('/members/do_action.php?actionname=untaguser&user=<?php echo $user; ?>&referrer=viewusers')">Untag <?php echo $row['firstname']; ?></a>
<?php } 
		
		if ($_SESSION['level'] == "admin")
		{
?>
		
		<br /><img src="/img/arrow_red.gif" /><a href="#" onclick="ShowMessage('delete', 1, '<?php echo $user; ?>');">Delete</a>

<?php
		}
		
		?>
		<div class="horizontal_separation"></div>
	</td>



<?php

	}
	

?>


	</tr>

</table>
</span>